package org.feng.common;

import java.util.HashMap;
import java.util.Objects;

/**
 * 值不能为空的 map
 *
 * @version v1.0
 * @author: fengjinsong
 * @date: 2022年06月16日 22时28分
 */
public class ValueNonNullHashMap extends HashMap<String, Object> {
    private static final long serialVersionUID = -2277909086011477919L;

    public ValueNonNullHashMap() {
        super(16);
    }

    @Override
    public Object put(String key, Object value) {
        if (Objects.isNull(value)) {
            throw new ValueNonNullException();
        }
        return super.put(key, value);
    }

    private static class ValueNonNullException extends IllegalArgumentException {
        public ValueNonNullException() {
            super("键、值均不能为空");
        }

        private static final long serialVersionUID = -8817618003852408948L;
    }
}
